package com.liaoyegui.springboot.controller.wx;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.liaoyegui.springboot.common.Result;
import com.liaoyegui.springboot.entity.Order;
import com.liaoyegui.springboot.service.IOrderService;
import io.swagger.models.auth.In;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/wx/order")
public class WxOrderController {
    @Resource
    private IOrderService orderService;

    /*
     * 购买商品
     * */
    @PostMapping("/users/buy")
    public Result productBuy(@RequestBody Order order){
        orderService.buyProduct(order);
        return Result.success();
    }

    /*
    * 查询订单
    * */
    @GetMapping("/getinfo/byid")
    public Result getOrderById(@RequestParam String state){
        if(state.equals("3")){
            List<Order> list = orderService.list();
            return Result.success(list);
        } else {
            LambdaQueryWrapper<Order> wrapper = new LambdaQueryWrapper<>();
            wrapper.eq(Order::getState, state);
            List<Order> list = orderService.list(wrapper);
            return Result.success(list);
        }
    }

    @PostMapping("/update")
    public Result updateOrderStatus(@RequestBody Order order){
        orderService.saveOrUpdate(order);
        return Result.success();
    }

}
